#include <REGX52.H>


//独立按键私有延时函数   @11.0592MHz   20ms
void Key_Delay()
{
	unsigned char i, j;

	i = 36;
	j = 217;
	do
	{
		while (--j);
	} while (--i);
}


/**
  * @brief  获取独立按键键码
  * @param  无
  * @retval 按下按键的键码，范围：0~4，无按键按下时返回值为0
  */
unsigned char Key()
{
	unsigned char KeyNumber=0;
	
	if(P3_1==0){ Key_Delay();while(P3_1==0); Key_Delay();KeyNumber=1;}
	if(P3_0==0){ Key_Delay();while(P3_0==0); Key_Delay();KeyNumber=2;}
	if(P3_2==0){ Key_Delay();while(P3_2==0); Key_Delay();KeyNumber=3;}
	if(P3_3==0){ Key_Delay();while(P3_3==0); Key_Delay();KeyNumber=4;}
	
	return KeyNumber;
}
